using System;
using System.Configuration;
using System.Web;
using System.Xml;
using System.Xml.Xsl;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2006-03-08	
	Status:		release	
	Version:	2.0.0
	Build:		20080401
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/

/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20070524:	Modification for .Net 2.0
	20080401:	Minor modifications for performance profiling
	-----------------------------------------------------------------------	*/

namespace umlungu.engineX.blogX {
	/// <summary>
	/// umlungu engineX blog and site page base class.
	/// </summary>
	public class pageX : System.Web.UI.Page {
		#region Invisible properties
		private string label;
		#endregion

		#region Visible properties
		private DateTime starttime;
		/// <summary>Start time marker</summary>
		/// <value>A date-time object created first thing in the constructor to mark the beginning of code execution</value>
		public DateTime StartTime {
			get { return starttime; }
			set { starttime = value; }
		}
		private x_debug debugger;
		/// <summary>Debugging flag</summary>
		/// <value>Debug set to true if debugging mode anabled</value>
		public bool Debug {
			get { return debugger.Enabled; }
			// set { debugger.Enabled = value; }	... set via debug object 'Status' property
		}
		/// <summary>Tracking flag</summary>
		/// <value>Track set to true if tracking mode anabled</value>
		public bool Track {
			get { return debugger.Tracking; }
		}
		/// <summary>Debugging object</summary>
		/// <value>Debugger created if debugging mode anabled</value>
		public x_debug Debugger {
			get { return debugger; }
		}
		private x_config config;
		/// <summary>Configuration object</summary>
		/// <value>Configuration values acces via the object</value>
		public x_config Config {
			get { return config; }
		}
		#endregion

		#region Constructors/Destructors
		/// <summary>Constructor</summary>
		public pageX(string lbl) : base() {
			starttime = DateTime.Now;
			label = lbl;
			debugger = new x_debug(Server.MapPath(String.Concat("debug/", label, ".xml")), starttime);
			config = new x_config();
		}
		#endregion

		#region Public methods
		/// <summary>Get a form field or querystring parameter (form default)</summary>
		public string FormOrQuery(string param) {
			return (FormField(param) == "")? QueryParam(param) : FormField(param);
		}
		/// <summary>Get a form field or querystring parameter (query default)</summary>
		public string QueryOrForm(string param) {
			return (QueryParam(param) == "")? FormField(param) : QueryParam(param);
		}
		/// <overloads>Get a query string parameter</overloads>
		/// <summary>Default value supplied</summary>
		public string QueryParam(string param, string defaultValue) {
			return getRequest(false, param, defaultValue);
		}
		/// <summary>Default value is ""</summary>
		public string QueryParam(string param) {
			return getRequest(false, param, "");
		}
		/// <overloads>Get a form field</overloads>
		/// <summary>Default value supplied</summary>
		public string FormField(string param, string defaultValue) {
			return getRequest(true, param, defaultValue);
		}
		/// <summary>Default value is ""</summary>
		public string FormField(string param) {
			return getRequest(true, param, "");
		}
		#endregion

		#region Protected methods
		/// <summary>
		/// Checks and returns the first spaces name in the delimited list.
		/// </summary>
		protected string getRequest(bool isform, string param, string def) {
			if (isform)
				return (Request.Form[param] == null)? def: Request.Form[param];
			else
				return (Request.QueryString[param] == null)? def: Request.QueryString[param];
		}
		#endregion

		#region Private methods
		#endregion
	}
}
